package com.wjboot.realty.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wjboot.common.util.R;
import com.wjboot.realty.model.RealtyType;
import com.wjboot.realty.service.RealtyTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 房产类型
 *
 * @author Wangjing
 * @date 2023-03-13 10:37:24
 */

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/realty/realtytype" )
public class RealtyTypeController {

    private final  RealtyTypeService realtyTypeService;

    /**
     * 分页查询
     */
    @GetMapping("/page" )
    @SaCheckPermission("realty_realtytype_view" )
    public R getRealtyTypePage(Page page, RealtyType realtyType) {
        return R.ok(realtyTypeService.page(page, Wrappers.query(realtyType)));
    }


    @GetMapping("/{id}" )
    @SaCheckPermission("realty_realtytype_view" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(realtyTypeService.getById(id));
    }


    @PostMapping
    @SaCheckPermission("realty_realtytype_add" )
    public R save(@RequestBody RealtyType realtyType) {
        return R.ok(realtyTypeService.save(realtyType));
    }


    @PutMapping
    @SaCheckPermission("realty_realtytype_edit" )
    public R updateById(@RequestBody RealtyType realtyType) {
        return R.ok(realtyTypeService.updateById(realtyType));
    }


    @DeleteMapping("/{id}" )
    @SaCheckPermission("realty_realtytype_del" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(realtyTypeService.removeById(id));
    }


}
